package com.bsj.travel.mqtt.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * @author yinhao
 * @version 1.0
 * @description mqtt redis key 汇总，方便统一管理
 * @date 2023/11/9
 */
@Getter
@RequiredArgsConstructor
public enum RedisKeys {
    /**
     * mqtt 服务端节点 key -> nodeName, value -> hostName
     */
    SERVER_NODES("mqtt:server:nodes:"),
    /**
     * mqtt <-> redis pub/sub 集群内消息交互
     */
    REDIS_CHANNEL_EXCHANGE(RedisKeys.REDIS_CHANNEL_EXCHANGE_KEY),
    /**
     * 云端 -> 设备redis pub/sub 下行数据通道，广播到mqtt集群
     */
    REDIS_CHANNEL_DOWN(RedisKeys.REDIS_CHANNEL_DOWN_KEY),
    /**
     * 连接状态存储
     */
    CONNECT_STATUS("mqtt:connect:status:"),

    /**
     * 设备连接所在节点存储
     */
    CONNECT_NODE("mqtt:connect:node:"),

    /**
     * 遗嘱消息存储
     */
    MESSAGE_STORE_WILL("mqtt:messages:will:"),
    /**
     * 保留消息存储
     */
    MESSAGE_STORE_RETAIN("mqtt:messages:retain:"),
    ;

    private final String key;

    /**
     * 用于拼接key的后缀
     * @param suffix 后缀
     * @return 完整的redis key
     */
    public String getKey(String suffix) {
        return this.key.concat(suffix);
    }

    public static final String REDIS_CHANNEL_EXCHANGE_KEY = "mqtt:channel:exchange";
    public static final String REDIS_CHANNEL_DOWN_KEY = "mqtt:channel:down";
}
